# _*_ coding: utf-8 _*_
# @Time : 2020/10/20 20:50
# @Author : moran office
# File : 3gbizhi.py
# Software : PyChram

import requests
from bs4 import BeautifulSoup
import json
import os
import sys
import io
from urllib import parse # 为了解决url编码的问题
path = 'E:/py/'
url = 'https://www.3gbizhi.com/sjbz/'
# 请求头
refer = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'

}
# 解决url加密
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
response = requests.get(url, headers = refer)
# response.encoding = response.apparent_encoding
data=response.content.decode('utf-8')
# print(data)

soup = BeautifulSoup(data, "html.parser")

'''
tmenu = soup.find('ul', class_= 'tmenu')
li_list = tmenu.find_all('li')
for li in li_list:
    # print(li.text)
    # 获得li标签
    a = li.find('a')
    print(a["href"])
    '''
# 获取手机壁纸

div = soup.find('div', class_ = 'contlistw')
ul = div.find('ul', class_ = 'cl')
li_list = ul.find_all('li')

for li in li_list:
    a = li.find('a', class_ = 'imgw')
    img = a.find('img')
    #print(img)
    print(img["lazysrc"])
    file_name = img["title"]
    html = requests.get(img["lazysrc"])
    f = open(path + file_name + '.jpg', 'wb')
    f.write(html.content)
    f.close()














